#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
Py40 PyQt5 tutorial 

In this example, we connect a signal
of a QSlider to a slot of a QLCDNumber. 

author: Jan Bodnar
website: py40.com 
last edited: January 2015
"""

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QWidget, QLCDNumber, QSlider, QVBoxLayout, QApplication,QTextEdit)
from PyQt5.QtGui import QColor,QFont


class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):
        
        self.textEdit = QTextEdit()
        self.textEdit.setFont(QFont('Arial Black', 20))#设置字体

        sld = QSlider(Qt.Horizontal, self)  #添加一个水平滑动条
        sld.setMinimum(0)                   #设置最小值
        sld.setMaximum(100)                 #设置最大值
        sld.setRange(0,100)                 #设置范围
        sld.setFixedSize(480,30)            #设置控件大小

        vbox = QVBoxLayout()                #添加一个竖直盒子布局
        vbox.addWidget(self.textEdit)
        vbox.addWidget(sld)

        self.setLayout(vbox)
        sld.valueChanged[int].connect(self.sliderChangeValue) #滑块值变化时连接到函数
        
        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('Slider Edit')
        self.show()

    def sliderChangeValue(self,value):
        self.textEdit.setTextColor(QColor(0,0,255,127)) #设置字体颜色
        self.textEdit.setFontPointSize(96)  #设置字体大小
        self.textEdit.setText(str(value))   #设置文本
        #self.textEdit.toPlainText()        #返回文本
        

if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

